import java.util.Scanner;

public class test {
//    根据键盘录入学生的姓名和年龄，封装成为student学生对象
    public static void main(String[] args)  {
        Student stu=new Student();
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入学生姓名：");
            String name=sc.nextLine();
            stu.setName(name);
            System.out.println("请输入学生年龄:");
            int age=0;

        while(true){
            try {
                age=Integer.parseInt(sc.nextLine());
                stu.setAge(age);
                break;

            } catch (NumberFormatException e) {
//            throw new RuntimeException(e);
                System.out.println("年龄输入有误，请输入整数年龄!");
            } catch (Exception e) {
//                throw new RuntimeException(e);
                String message=e.getMessage();
                System.out.println(message);
            }
        }

        System.out.println("学生姓名是:"+stu.getName()+",年龄是:"+stu.getAge()+"岁");
    }
}
